<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Report extends arfaController {

	public function __construct(){
		parent::__construct();
		$this->load->helper('general');
		$this->cekLogin();
		$this->load->model("m_kuesioner_model");
		$this->load->model("m_ijin_model");
		$this->load->model("m_tindak_lanjut_model");
		$this->load->model("m_kritik_saran_model");
		$this->load->model("m_tanya_model");
	}

	public function r_global(){
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		if($this->form_validation->run() == FALSE){
			$data["content"]	= $this->load->view("form_r_global","",true);
			$data["menu"] 		= "admin";
			$this->load->view("main",$data);
		} else {
			$data["query"]	= $this->m_kuesioner_model->get_chart(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))));
			$data["query3"]	= $this->m_kuesioner_model->get_chart_usia(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))));
			$data["query4"]	= $this->m_kuesioner_model->get_chart_perkerjaan(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))));
			$data["query5"]	= $this->m_kuesioner_model->get_chart_pendidikan(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))));
			$data["query6"]	= $this->m_kuesioner_model->get_chart_izin(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))));
			$data["query2"]	= $this->m_kuesioner_model->get_chart_bar(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))));
			$data["content"]	= $this->load->view("chart_r_global",$data,true);
			$data["menu"] 		= "admin";
			$this->load->view("main",$data);
		}
	}

	public function r_global_perdinas(){
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		if($this->form_validation->run() == FALSE){
			$data["menu"]		= "admin";
			$data["content"]	= $this->load->view("form_r_global_perdinas",$data,true);
			$this->load->view("main",$data);
		} else {
			$query = $this->m_ijin_model->get_by("STATUS","1");
			$data["list_izin"]			= $query;
			$a=0;
			foreach ($query as $row) {
				$data["query_".$a."_1"]	= $this->m_kuesioner_model->get_chart_perdinas(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))),$query[$a]["ID_IJIN"]);
				$data["query_".$a."_2"]	= $this->m_kuesioner_model->get_chart_bar_perdinas(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))),$query[$a]["ID_IJIN"]);
				$data["query_".$a."_3"]	= $this->m_kuesioner_model->get_chart_usia_perdinas(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))),$query[$a]["ID_IJIN"]);
				$data["query_".$a."_4"]	= $this->m_kuesioner_model->get_chart_perkerjaan_perdinas(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))),$query[$a]["ID_IJIN"]);
				$data["query_".$a."_5"]	= $this->m_kuesioner_model->get_chart_pendidikan_perdinas(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))),$query[$a]["ID_IJIN"]);
				$data["query_".$a."_6"]	= $this->m_kuesioner_model->get_chart_izin_perdinas(date("Y-m-d",strtotime($this->input->post("tgl_awal"))),date("Y-m-d",strtotime($this->input->post("tgl_akhir"))),$query[$a]["ID_IJIN"]);
				$a++;
			}
			// dump($data);
			$data["content"]	= $this->load->view("chart_r_global_perdinas",$data,true);
			$data["menu"] 	 	= "admin";
			$this->load->view("main",$data);
		}
	}

	public function r_dinas(){
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		if($this->form_validation->run() == FALSE){
			$data["content"]= $this->load->view("form_r_dinas","",true);
			$data["menu"]	= "admin";
			$this->load->view("main",$data);
		} else {
			$this->load->model(array("m_ijin_model","m_tanya_model"));
			$data["tanya"]	= $this->m_tanya_model->get_by(array("STATUS"=>1));
			$data["ijin"]	= $this->m_ijin_model->get_by(array("STATUS"=>1));
			$data["tgl_awal"]	= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]	= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			$data["content"]	= $this->load->view("chart_r_dinas",$data,true);
			$data["menu"] 		= "admin";
			$this->load->view("main",$data);
		}
	}

	public function r_periode(){
		$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
		$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		if($this->form_validation->run() == FALSE){
			$data["content"]= $this->load->view("form_r_dinas","",true);
			$data["menu"]	= "admin";
			$this->load->view("main",$data);
		} else {
			$this->load->model(array("m_tanya_model","m_kuesioner_model"));
			$data["tgl_awal"]	= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]	= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			$data["tanya"]		= $this->m_tanya_model->get_by(array("STATUS"=>1));
			$data["kuesioner"]	= $this->m_tanya_model->get_nilai_periode($data["tgl_awal"],$data["tgl_akhir"]);
			$data["content"]	= $this->load->view("chart_r_periode",$data,true);
			$data["menu"] 		= "admin";
			$this->load->view("main",$data);
		}
	}

	public function r_ikm()
	{
		$this->form_validation->set_rules("tgl_awal", "Tanggal Awal", "required");
		$this->form_validation->set_rules("tgl_akhir", "Tanggal Akhir", "required");
		$this->form_validation->set_rules("laporan", "Jenis Laporan IKM", "required");

		if( $this->form_validation->run() == FALSE ) {
			$data["content"]= $this->load->view("form_r_ikm","",true);
			$data["menu"]	= "admin";
			$this->load->view("main",$data);
		} else {
			$data["tgl_awal"]		= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]		= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			if( $this->input->post("laporan") == "karakteristik" ) {
				$data["laporan_jk"] 		= $this->m_kuesioner_model->get_jenis_kelamin($data["tgl_awal"],$data["tgl_akhir"]);
				$data["laporan_usia"] 		= $this->m_kuesioner_model->get_chart_usia($data["tgl_awal"],$data["tgl_akhir"]);
				$data["laporan_pendidikan"] = $this->m_kuesioner_model->get_chart_pendidikan($data["tgl_awal"],$data["tgl_akhir"]);
				$data["laporan_pekerjaan"] 	= $this->m_kuesioner_model->get_chart_perkerjaan($data["tgl_awal"],$data["tgl_akhir"]);
				$data["laporan_izin"] 		= $this->m_kuesioner_model->get_chart_izin($data["tgl_awal"],$data["tgl_akhir"]);
				$this->load->library("phpexcel");
				$this->load->library("PHPExcel/IOFactory");
				$this->load->view("report_ikm_karakteristik",$data,true);
			} else {
				$data["laporan"]	= $this->m_tanya_model->get_report_ikm_unsur($data["tgl_awal"],$data["tgl_akhir"]);
				$this->load->library("phpexcel");
				$this->load->library("PHPExcel/IOFactory");
				$this->load->view("report_ikm_unsur",$data,true);
			}
		}
	}

	public function r_tindak_lanjut() {
		$this->form_validation->set_rules("tgl_awal", "Tanggal Awal", "required");
		$this->form_validation->set_rules("tgl_akhir", "Tanggal Akhir", "required");
		$this->form_validation->set_rules("sord", "Pengurutan", "required");

		if( $this->form_validation->run() == FALSE ) {
			$data["content"]= $this->load->view("form_r_tindak_lanjut","",true);
			$data["menu"]	= "admin";
			$this->load->view("main",$data);
		} else {
			$data["tgl_awal"]	= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]	= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			$data["sord"] 		= ($this->input->post("sord") == "tanggal_dibuat") ? "tanggal_dibuat" : "deadline" ;
			$data["jumlah"]		= $this->m_tindak_lanjut_model->get_jumlah($data["tgl_awal"],$data["tgl_akhir"],$data["sord"]);
			$data["content"]	= $this->load->view("table_r_tindak_lanjut",$data,true);
			$data["menu"] 		= "admin";
			$this->load->view("main",$data);
		}
	}

	public function r_kritik_saran()
	{
		$this->form_validation->set_rules("tgl_awal", "Tanggal Awal", "required");
		$this->form_validation->set_rules("tgl_akhir", "Tanggal Akhir", "required");

		if( $this->form_validation->run() == FALSE ) {
			$data["content"]= $this->load->view("form_r_kritik_saran","",true);
			$data["menu"]	= "admin";
			$this->load->view("main",$data);
		} else {
			$data["tgl_awal"]		= date("Y-m-d",strtotime($this->input->post("tgl_awal")));
			$data["tgl_akhir"]		= date("Y-m-d",strtotime($this->input->post("tgl_akhir")));
			$data["jumlah"] 		= $this->m_kritik_saran_model->get_jumlah($data["tgl_awal"],$data["tgl_akhir"]);
			$data["content"]		= $this->load->view("table_r_kritik_saran",$data,true);
			$data["menu"] 			= "admin";
			// dump($data);
			$this->load->view("main",$data);
		}
	}
}